package cn.itzzx.resume.controller;

import cn.itzzx.resume.request.LoginRequest;
import cn.itzzx.resume.response.Response;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * TODO
 *
 * @author Martin
 * @since 1.0
 */
@RestController
public class LoginController {

    @RequestMapping("login")
    public @ResponseBody Response login(@RequestBody LoginRequest request,
                                        HttpSession session){
        if("admin".equals(request.getUserName()) && "admin".equals(request.getPassword())){
            //登陆成功 保存用户信息
            session.setAttribute("user", "userInfo");
            return Response.builder(200,"登陆成功");
        }
        return Response.builder(400,"登陆失败");
    }


    @RequestMapping("getSessionId")
    @ResponseBody
    public String getSessionId(HttpSession session){
        return session.getId();
    }


}
